
const refs = {
    //校验正则表达式
    email : /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
    number: /^[0-9]+$/,
    password: /^[a-zA-Z0-9_-]{8,18}$/
}

const verify = (rule,value,refs,callback)=>{
    if(value){
        if(refs.test(value)){
            callback()
        }else{
            callback(new Error(rule.message))
        }
    }else{
        callback()
    }
}

export default{
    email:(rule,vale,callback)=>{
        return verify(rule,vale,refs.email,callback)
    },
    number:(rule,vale,callback)=>{
        return verify(rule,vale,refs.number,callback)
    },
    password:(rule,vale,callback)=>{
        return verify(rule,vale,refs.password,callback)
    }
}